package name.vaccari.matteo.tai.phonedirectory.htmlbuilder;

import static org.junit.Assert.*;

import name.vaccari.matteo.tai.phonedirectory.web.BaseViewTestCase;

import org.junit.Test;
import org.w3c.dom.Document;


public class HtmlBuilderTest extends BaseViewTestCase {

	@Test
	public void htmlElementTest() throws Exception {
		Html element = new Html();
		String build = element.build();
		assertEquals("<html>\n</html>", build);
	}
	
	@Test
	public void testWithChildren() throws Exception {
		Html html = new Html();
		GenericElement head = new Head();
		html.add(head);
		String build = html.build();
		assertEquals("<html>\n<head>\n</head>\n</html>", build);
	}
	
	@Test
	public void testStylesheetLinkTag() throws Exception {
		String actual = new StylesheetLinkTag("foo").build();
		String expected = "<link rel=\"stylesheet\" href=\"foo.css\" type=\"text/css\">\n</link>";
		assertEquals(expected, actual);
	}
	
	@Test
	public void testBig() throws Exception {
		String html =
			new Html().add(
			  new Head().add(
			    new Title("My Title!"),
			    new StylesheetLinkTag("scaffold")
			  ),
			  new Body().add(
			    new H1("Big Products!"),
			    new Paragraph("first paragraph").with("style", "color: green")    
			  )
			).build();
		Document document = documentFromString(html);
		assertEquals("My Title!", getNodeContent(document, "/html/head/title"));
		assertEquals(1, getNodeList(document, "/html/head/link[@rel='stylesheet']").getLength());
	}
}
